﻿using System.Data.SqlTypes;
using System.Data.Sql;
using System.Data.SqlClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ThinkGeo.MapSuite.Core;
using Microsoft.SqlServer.Types;
using ThinkGeo.MapSuite.WebEdition;
namespace SensorNetworkUI

{
    public partial class Map : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                
                Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF"));
                Map1.CurrentExtent = new RectangleShape(-131.22, 55.05, -54.03, 16.91);
                Map1.MapUnit = GeographyUnit.DecimalDegree;

                WorldMapKitWmsWebOverlay worldMapKitOverlay = new WorldMapKitWmsWebOverlay();
                Map1.CustomOverlays.Add(worldMapKitOverlay);

                if (Session["username"] == null)
                    Response.Redirect("~/login.aspx");  
                foreach (NetworkDataStructure ns in ((UserDataStructure)Session["username"]).AllowedNetworks)
                {
                    double averagetemp = ns.Average;

                    InMemoryMarkerOverlay markerOverlay = new InMemoryMarkerOverlay(ns.Name);
                    markerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.Popup.ContentHtml = "<div style='font-size: 11px;'>" + ns.Name + "<br />Average Temperature = " + averagetemp + "</div>";
                    markerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.Popup.HasCloseButton = true;
                    markerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.Popup.Width = 100;
                    markerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.Popup.Height = 50;
                    markerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.Popup.BackgroundColor = GeoColor.StandardColors.LightBlue;
                    markerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.Popup.BorderColor = GeoColor.StandardColors.Black;
                    markerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.Popup.BorderWidth = 1;
                    markerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.WebImage.ImageOffsetX = -10.5f;
                    markerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.WebImage.ImageOffsetY = -25f;
                    markerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.WebImage.ImageWidth = 21;
                    markerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.WebImage.ImageHeight = 25;
                    markerOverlay.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

                    Map1.CustomOverlays.Add(markerOverlay);
                    //markerOverlay.Features.Add("Kansas", new Feature(-94.558, 39.078));
                    Feature p = new Feature();


                    //markerOverlay.Features.Add("Detroit", new Feature(-95.558, 39.078));

                    foreach (SensorStructure st in ns.Sensors)
                    {

                        if (!markerOverlay.Features.Contains(st.Name))
                            markerOverlay.Features.Add(st.Name, new Feature(st.Longitude, st.Lattitude));

                    }
                    //Global.users.RemoveAt(0);

                }

                //Map1.MapUnit = GeographyUnit.DecimalDegree;
                //Map1.MapTools.OverlaySwitcher.Enabled = true;
                //Map1.MapTools.MouseCoordinate.Enabled = true;
                //GoogleOverlay google = new GoogleOverlay("Google Map");
                //google.JavaScriptLibraryUri = new Uri(@"http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAoxK_HcqphMsnUQHEwLwHlRSavkNJi0NVTgm4UDidoiIU5dUJpRQW88FufPCp0aTPraxZgZFAIUHn3Q");
                //google.GoogleMapType = GoogleMapType.Normal;


                //WorldMapKitWmsWebOverlay worldMapKitOverlay = new WorldMapKitWmsWebOverlay();
                //Map1.CustomOverlays.Add(worldMapKitOverlay);
             //   Map1.CustomOverlays.Add(google);
                // markerOverlay.Features.Add("Kansas", new Feature(-94.558, 39.078));


              //  ContextMenu onmap = new ContextMenu();
              





                ContextMenu onmap = new ContextMenu("area", 180);
                ContextMenuItem pos = new ContextMenuItem("Position");
                pos.Click += new EventHandler<ContextMenuItemClickEventArgs>(showpos);
                onmap.MenuItems.Add(pos);

                Map1.ContextMenu = onmap;
                
            }
        }
        private void showpos(object sender, ContextMenuItemClickEventArgs e)
        {


        }
       
    }
}